from pydantic import BaseModel, Field
from datetime import datetime


class UserCreate(BaseModel):
    username: str = Field(..., min_length=3, max_length=32, description="用户名")
    password: str = Field(..., min_length=6, max_length=128, description="密码")


class UserLogin(BaseModel):
    username: str = Field(..., min_length=3, max_length=32, description="用户名")
    password: str = Field(..., min_length=6, max_length=128, description="密码")
    time: int = Field(..., description="13位带校验位的时间戳")


class Token(BaseModel):
    access_token: str
    token_type: str = "bearer"


class UserInfo(BaseModel):
    username: str
    create_time: datetime
    last_login_time: datetime | None = None
    login_count: int | None = 0
    last_login_ip: str | None = None
    role: str
    bio: str | None = None
    avatar: str


class ChangePassword(BaseModel):
    old_password: str = Field(..., min_length=6, max_length=128, title="title老密码，至少6位",
                              description="老密码，至少6位")
    new_password: str = Field(..., min_length=6, max_length=128, title="title新密码，至少6位",
                              description="新密码，至少6位")
